Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Language Guide / Part 2 - AppleScript Language Reference
Chapter 9 - Script Objects / Inheritance and Delegation


The Parent Property and the Current Application

The default parent property for any script that doesn't explicitly declare one is the default target application--usually, the application that is running the script, such as the Script Editor. You can use the predefined variable current application to refer to either the default target application or whatever application is currently set as a script's parent property.

You can make any application the current application for a script or script object simply by declaring it as a parent property. Any subsequent command in the script for which the script doesn't have a handler is passed to the application you declare as the parent, and subsequent occurrences of the constant current application refer to that application.

For example, this script declares the Scriptable Text Editor as its parent property, then sends commands that close the Scriptable Text Editor's frontmost window and return the application's name:

property parent: application "Scriptable Text Editor"close front window
tell current application to return my name
In this case, my refers to the current application (Scriptable Text Editor). The Tell statement is optional; just return the name of me would produce the same result, because AppleScript sends the command to the Scriptable Text Editor. If you remove the property declaration from the script, the Script Editor becomes the current application. When sent to the Script Editor, the Close command and the Return statement produce errors because the Script Editor doesn't understand them.

In the next example, the script Bilbo declares the Scriptable Text Editor as
its parent property and includes a handler that modifies the behavior of
the scripting addition command Display Dialog.

script Bilbo
   property parent : application "Scriptable Text Editor"   on display dialog x
      tell application "Script Editor" to display dialog ¬
         "Scriptable Text Editor has something to say"      continue display dialog x
   end display dialog
end script

tell Bilbo to display dialog "Hello"
Because the script object Bilbo declares the Scriptable Text Editor as its parent property, the on display dialog handler must use a Tell statement to send a separate Display Dialog command to the Script Editor. The handler then uses a Continue statement to pass the original Display Dialog command to the Scriptable Text Editor, which becomes the frontmost application and uses the Display Dialog addition to display "Hello".


Previous Book Contents Book Index Next

© Apple Computer, Inc.
13 JUL 1996